/*
CoE 1186

1186 Entertainment
Reversi Game

ReversiGameRoom.java


-----------------------------------------
ReversiGameRoom

	- Abstract or Concrete:  Concrete
	- List of Superclasses:  GameRoom
	- List of Subclasses:  N/A
	- Purpose:  GUI pane representing a Reversi Game Room screen
	- Collaborations:  Loaded by the ClientApplet, sends commands to Server through the ClientApplet
---------------------
	- Attributes:
		- ReversiGameBoard board
			-> Reversi implementation of GameBoard abstract class.  Handles all moves and manages the rules; including win/lose conditions.
---------------------
	- Operations:
		- void paint(Graphics g)
			-> Paints any custom graphics.
---------------------
	- Constraints:  N/A

-----------------------------------------
*/

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


//Game room GUI where the game takes place
public class ReversiGameRoom extends GameRoom
{

	ReversiGameBoard board;
	JPanel boardPane, gameMessagePane;
	JLabel gamePieceLbl, statusLbl;
	JTextField gamePieceFld, statusFld;
	int p1id, p2id;
	boolean i_forfeit;

	public ReversiGameRoom(ClientApplet ca1, String player1, int player1id, String player2, int player2id)
	{
		super(ca1, "Reversi Game Room", player1, player1id, player2, player2id, "View Rules", "Forfeit Game", "Reversi");
		setBoardPane();
		setPreferredSize(new Dimension(700,500));
		setMessagePane();

		i_forfeit = false;

	}

	public void setBoardPane()
	{
		boardPane = new JPanel(new FlowLayout());
		board = new ReversiGameBoard(ca,this,p1id,p2id);
		boardPane.add(board);

		this.add(boardPane, BorderLayout.CENTER);
	}


	public void setMessagePane()
	{
		gamePieceLbl = new JLabel("Your game piece color:");
		statusLbl = new JLabel("Status: ");
		gamePieceFld = new JTextField();
		gamePieceFld.setBackground(this.getBackground());
		gamePieceFld.setBorder(BorderFactory.createEmptyBorder());
		gamePieceFld.setEditable(false);
		statusFld = new JTextField();
		statusFld.setBackground(this.getBackground());
		statusFld.setBorder(BorderFactory.createEmptyBorder());
		statusFld.setEditable(false);

		gameMessagePane = new JPanel(new GridLayout(4,1));
		//top, left, bottom, right
		gameMessagePane.setBorder(BorderFactory.createEmptyBorder(0,0,15,0));
		gameMessagePane.add(gamePieceLbl);
		gameMessagePane.add(gamePieceFld);
		gameMessagePane.add(statusLbl);
		gameMessagePane.add(statusFld);
		sidePane.add(gameMessagePane, BorderLayout.NORTH);
	}


	public void setGamePieceText(String text)
	{
		gamePieceFld.setText(text);
	}

	public void setStatusText(String text)
	{
		statusFld.setText(text);
	}

	public void setGameEnd()
	{
		forfeitBtn.setText("Close Game");
	}



	public void receiveGameForfeit()
	{
		if( i_forfeit )
		{
			// register a forfeit
			ca.send("23" + DELIM + myId + DELIM + "3");
		}
		else
		{
			// display message and register as a win
			JOptionPane.showMessageDialog(this,"Your opponent has forfeited the game.", "Message", JOptionPane.PLAIN_MESSAGE);
			ca.send("23" + DELIM + myId + DELIM + "1");
		}
		ca.send("4" + DELIM + "0");
	}


	public void sendGameForfeit()
	{
		i_forfeit = true;
		ca.send("25"+DELIM);
	}


/*
	public static void main(String [] args)
	{
		JFrame mainFrame = new JFrame("Reversi Game Room");


		ClientApplet ca1 = new ClientApplet();
		String p1="Player 1";
		String p2="Player 2";
		ReversiGameRoom roomPane = new ReversiGameRoom(ca1,p1,p2);
		roomPane.setGamePieceText("white");
		roomPane.setStatusText("It is Player2's turn.");

		mainFrame.add(roomPane);
		mainFrame.setSize(700,500);
		mainFrame.setVisible(true);


		mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
*/
} //end of ReversiGameRoom class